home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 588 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  43 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: simpsondg@aol.com (SimpsonDG)
  3. Newsgroups: comp.lang.c
  4. Subject: gets() question
  5. Date: 7 Jan 1996 11:31:11 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4cosgf$rir@newsbf02.news.aol.com>
  9. Reply-To: simpsondg@aol.com (SimpsonDG)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. Can any of you C gurus out there help me with this?  I have a problem with
  13. gets() that I don't understand.  The program below will successfully input
  14. the string s[0], but will simply ignore the gets() that inputs s[1] and
  15. goes on to ask for i[1].  What's the deal?  A little experimenting seems
  16. to indicate that the problem arises when I have a gets() following a
  17. scanf() -- e.g., a program using only gets() or only scanf() works fine.
  18.  
  19. David Simpson
  20.  
  21. --------------------------------------------------------------------------
  22. -------------------
  23.  
  24. #include "stdio.h"
  25.  
  26. void main(void)
  27. {
  28.    int i[5];
  29.    char s[3][10];
  30.  
  31.    printf ("Enter s[0]:  ");
  32.    gets (s[0]);
  33.  
  34.    printf ("Enter i[0]]:  ");
  35.    scanf ("%d",&i[0]);
  36.  
  37.    printf ("Enter s[1]:  ");
  38.    gets (s[1]);                  /* this gets() doesn't wait for input */
  39.  
  40.    printf ("Enter i[1]]:  ");
  41.    scanf ("%d",&i[1]);
  42. }
  43.